function UserEditor(parent){
	this.parent = parent;
	this.context = undefined;
	this.close_cb = undefined;
}
UserEditor.prototype.loadUI = function(ui_url){
	$.ajax({
		url:ui_url,
		context:this
	}).done(function(data){
		var $parent = $(this.parent).html(data);
		var edit = this;
		$("input.ok_bt",$parent).button();
		$("form",this.$parent).ajaxForm({
			success:function(){
					edit.close();
				},
			error:function(){
				alert("error");
				edit.close();
				}
			}
		);
	});
}
UserEditor.prototype.close = function(){
	$(this.parent).toggle();
	if(this.close_cb != undefined) this.close_cb();
}


function UserTable($container,url){
	this.$container = $container;
	this.url = url;
	this.data = undefined;
}
UserTable.prototype.update = function(){
	$.ajax({
		url:this.url,
		dataType: 'json',
		context: this,
		success:function(data,status){
			this.updateData(data);
		}});
};
UserTable.prototype.updateData = function(data){
	var userTable = this;
	this.data = data;
	$("tr",this.$container).remove();
	$.each(data,function(index,user){
		userTable.addRow(index,user);
	});
	$("tr a",this.$container).click(function(evt){
		userTable.deleteRow($(this).attr("id"));
		evt.preventDefault();
	});
};

UserTable.prototype.deleteRow = function(index){
	$.ajax({
		url:"/www/queue_act.yaws?mod=user&action=del&id=" + this.data[index].id,
		dataType:'json',
		context:this,
		success:function(data,status){
			$("tr#" + index,this.$container).remove();
		}
	});
	//$("tr#" + index,this.$container).remove();
}
UserTable.prototype.addRow = function(index,user){
	$("tbody",this.$container).append("<tr id='" + index + "'>"
	+ "<td>" + user.id + "</td>" 
	+ "<td>" + user.login_name + "</td>"
	+ "<td>" + user.name + "</td>"
	+ "<td>" + user.mail + "</td>"
	+ "<td>" + user.im + "</td>"
	+ "<td>" + user.vendor_id + "</td>"
	+ "<td> <a href='#' id='" + index + "'> delete </a></td>"
	+ "</tr>");
};

